package com.wsj.spring.kafka.kafkademo;

import com.google.gson.Gson;
import com.wsj.spring.kafka.kafkademo.bean.Message;
import com.wsj.spring.kafka.kafkademo.provider.KafkaSender;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * spring kafka demo
 *
 * @author WangSongJun
 * @date 2018/6/30 21:45
 */
@SpringBootApplication
public class KafkaDemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(KafkaDemoApplication.class, args);
        KafkaSender sender = context.getBean(KafkaSender.class);
        for (int i = 0; i < 5; i++) {
            sender.send(new Gson().toJson(new Message(Long.valueOf(i), UUID.randomUUID().toString(), LocalDateTime.now())));
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
